import { deviceTypeMap, bindTypeMap, deviceStatusMap, originTypeMap, fixedAssetMap } from '@/config/dict'
import { byKeyGetItem } from '@/utils'
import { CustomStatus } from '@/components'

export const searchFormItem = [
  {
    type: 'input',
    key: 'deviceCode',
    label: '设备号'
  },
  {
    type: 'select',
    key: 'deviceType',
    label: '设备类型',
    options: deviceTypeMap
    // options: [{ key: 0, value: '全部' }, ...deviceTypeMap]
  },
  {
    type: 'select',
    key: 'bindType',
    label: '绑定类型',
    options: bindTypeMap
    // options: [{ key: 0, value: '全部' }, ...bindTypeMap]
  },
  {
    type: 'select',
    key: 'status',
    label: '状态',
    options: deviceStatusMap
    // options: [{ key: 0, value: '全部' }, ...deviceStatusMap]
  },
  {
    type: 'select',
    key: 'fixedAssets',
    label: '是否固定资产',
    labelWidth: '110px',
    options: fixedAssetMap
  }
]

export const tableColumn = (handleEdit, handleDelete) => {
  return [
    {
      key: 'name',
      label: '设备名称',
      minWidth: 200
    },
    {
      key: 'deviceCode',
      label: '设备号',
      minWidth: 220
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 140,
      render: (h, scope) => <CustomStatus list={deviceStatusMap} value={scope.row.status} />
    },
    {
      key: 'deviceType',
      label: '设备类型',
      minWidth: 120,
      render: (h, scope) => byKeyGetItem(deviceTypeMap, scope.row.deviceType).value
    },
    {
      key: 'bindType',
      label: '绑定类型',
      minWidth: 120,
      render: (h, scope) => byKeyGetItem(bindTypeMap, scope.row.bindType).value
    },
    {
      type: 'button',
      label: '操作',
      list: [
        {
          name: '修改',
          authKey: 'c_2',
          click: handleEdit
        },
        {
          name: '删除',
          authKey: 'c_3',
          confirm: '确定删除吗?',
          click: handleDelete
        }
      ]
    }
  ]
}

export const modalFormItem = (handleDeviceTypeChange, handleMapShow, disabled, isHide) => {
  return [
    {
      type: 'input',
      key: 'name',
      label: '设备名称',
      required: true,
      col: 12
    },
    {
      type: 'input',
      key: 'deviceCode',
      label: '设备号',
      otherAttrs: {
        disabled
      },
      required: true,
      col: 12
    },
    {
      type: 'select',
      key: 'deviceType',
      label: '设备类型',
      slotAttrs: {
        options: deviceTypeMap
      },
      required: true,
      slotListeners: {
        change: handleDeviceTypeChange
      },
      col: 12
    },
    {
      type: 'select',
      key: 'bindType',
      label: '绑定类型',
      slotAttrs: {
        options: bindTypeMap
      },
      required: true,
      col: 12
    },
    {
      type: 'input',
      key: 'assetCode',
      label: '资产号',
      col: 12
    },
    {
      type: 'input',
      key: 'factory',
      label: '厂家',
      col: 12
    },
    {
      type: 'input',
      key: 'modelCode',
      label: '型号',
      col: 12
    },
    {
      type: 'input',
      key: 'address',
      label: '设备位置',
      col: 12
    },
    {
      type: 'input',
      key: 'maintenanceMan',
      label: '维护人',
      col: 12
    },
    {
      type: 'input',
      key: 'maintenancePhone',
      label: '维护电话',
      col: 12
    },
    {
      type: 'select',
      key: 'originType',
      label: '来源',
      slotAttrs: {
        options: originTypeMap
      },
      col: 12
    },
    {
      type: 'input',
      key: 'price',
      label: '价值',
      col: 12
    },
    {
      type: 'input',
      key: 'ownership',
      label: '所有权',
      col: 12
    },
    {
      type: 'button',
      key: '',
      label: '所在坐标',
      isHide,
      required: true,
      slotAttrs: {
        name: '点击设置'
      },
      slotListeners: {
        click: handleMapShow
      },
      col: 12
    },
    {
      type: 'input',
      key: 'usages',
      label: '用途',
      slotAttrs: {
        style: { width: '94%' }
      },
      col: 24
    }
  ]
}

export const formButtons = (onSubmit, onReset) => {
  return {
    isDialog: true,
    submitName: '提交',
    resetName: '取消',
    submitCallback: values => onSubmit(values),
    resetCallback: () => onReset()
  }
}

// export const modalFormRules = {
//   name: [{ required: true, message: '请输入设备名称!', trigger: 'blur' }],
//   deviceCode: [{ required: true, message: '请输入设备号!', trigger: 'blur' }],
//   deviceType: [{ required: true, message: '请选择设备类型!', trigger: 'change' }],
//   bindType: [{ required: true, message: '请选择绑定类型!', trigger: 'change' }]
// }
